Meet JSON's functional half-brother.
If your business logic has a single-source-of-truth (SSOT) problem, JSOL may help.
I built JSOL because I didn't want to keep maintaining the same rules twice (once for the server, once again for the browser) on IPAX, a color science framework for accessible design systems. Every change meant updating both, testing both, and hoping they still agreed.
Did you know that something as simple as modulo can give you different results across languages? My LLM didn't. Turns out that 7.5 % 2 is 1.5 in JS… and 1 in PHP. And that's just one bug that slipped through code review.
Since most general-use languages today are somehow C-like, I wondered if there was some lingua franca we could use to declare business logic once, and include afterwards in our code with bit-for-bit parity.
That's how JSOL was born: a strict subset of JavaScript that transpiles to JavaScript, PHP, TypeScript and Python (with more targets planned), guaranteeing deterministic parity. Write the rule once, change it once, test it once.
Think JSON, but for business logic.
Is it worth your time?
The first question we developers ask about a new tool is: "Should I bother learning this?"
JSOL has strict syntax, zero syntactic sugar, and a learning curve. Writing it — even with an AI's help — will take you longer than writing native code you've already mastered. But JSOL's upfront cost can pay off in iterative maintenance.
The honest way to answer that question is with a model. So the first example below is exactly that: an adoption-economics model written in JSOL, running live in the REPL. And compiled to every target for inspection.
Play with the inputs: how many targets you maintain, how often your rules change, how many iterations until the upfront cost pays for itself. Add rows to evaluate different scenarios. And while you're at it, you're watching JSOL do what it was built to do.
(INPUT)
(OUTPUT)
Function: $mAdoptionEconomics
// @JSOL v0.2.96
/**
@description
# Adoption Economics - Full Model
Computes whether adopting JSOL for a given algorithm pays for itself,
using the break-even model from **ADOPTION_ECONOMICS.md**. Two paths are
compared: writing the algorithm by hand in every target language
("native"), versus writing it once in JSOL and adapting the compiled
output into each target ("jsol"). Each path has a setup cost (writing
it the first time) and a per-iteration cost (every later change).
## Cost Formulas
`setupCostNative = qTargets * (nDevCostSetup + nQaCostSetup)`
`setupCostJsol = nJsolWriteCostSetup + (qTargets * nHostAdaptationCostSetup) + nJsolQaCostSetup`
`iterationCostNative = qTargets * (nDevCostIteration + nQaCostIteration)`
`iterationCostJsol = nJsolWriteCostIteration + nJsolQaCostIteration + (qTargets * nHostAdaptationCostIteration)`
## Important Note
The naive version of this function returned a single "immediate win"
flag gated only on whether setup was cheaper. **That is wrong**: setup cost
and per-iteration cost can point in opposite directions, and collapsing
them into one flag hides real scenarios. There are four distinct cases,
from crossing `setupGap = setupCostJsol - setupCostNative` and
`perIterationSavings = iterationCostNative - iterationCostJsol`:
- **perIterationSavings > 0, setupGap <= 0**: JSOL cheaper now AND every
iteration going forward. *jsol_wins_always*, breakEven = 0.
- **perIterationSavings > 0, setupGap > 0**: JSOL starts more expensive
but each iteration closes the gap. *jsol_wins_after_breakeven*,
breakEven = setupGap / perIterationSavings (a future point).
- **perIterationSavings < 0, setupGap < 0**: JSOL starts cheaper but each
iteration is MORE expensive than native, eroding the lead.
*jsol_wins_until_expiration*, breakEven = setupGap /
perIterationSavings (a positive number: the point where native
catches back up and overtakes JSOL). A small value here means JSOL
is only cheaper for a sliver of a single iteration in practice.
- **Anything else** (JSOL starts more expensive AND stays more expensive
per iteration, or the two are permanently parallel with no
crossover): *native_always_wins*, breakEven = -1 (no finite point
exists).
## Important Disclaimer
This function makes no judgment about whether an algorithm will
actually see that many iterations; that estimate is the reader's to
make.
## Parameters
- **@param {integer} $qTargets** - N, number of target languages (e.g. 2 for JS+PHP).
- **@param {number} $nDevCostSetup** - D, native dev cost per target, first time.
- **@param {number} $nQaCostSetup** - Q, native QA cost per target, first time.
- **@param {number} $nJsolWriteCostSetup** - S, cost of writing the .jsol file itself, first time.
- **@param {number} $nHostAdaptationCostSetup** - H, cost of wiring compiled output into one target, first time.
- **@param {number} $nJsolQaCostSetup** - Q_jsol, cost of verifying the JSOL algorithm once, first time.
- **@param {number} $nDevCostIteration** - d, native dev cost per target, per later change.
- **@param {number} $nQaCostIteration** - q, native QA cost per target, per later change.
- **@param {number} $nJsolWriteCostIteration** - s, cost of changing the .jsol file, per later change.
- **@param {number} $nHostAdaptationCostIteration** - h, cost of re-wiring one target, per later change.
- **@param {number} $nJsolQaCostIteration** - q_jsol, cost of re-verifying the JSOL algorithm, per later change.
## Returns
- **@returns {Map}** - Returns a map with the following keys:
- **verdict**: One of the four cases above (*jsol_wins_always* | *jsol_wins_after_breakeven* | *jsol_wins_until_expiration* | *native_always_wins*)
- **breakEvenIterations**: -1 when no finite crossover exists
- **setupCostNative**: Total native setup cost
- **setupCostJsol**: Total JSOL setup cost
- **iterationCostNative**: Total native iteration cost
- **iterationCostJsol**: Total JSOL iteration cost
*/
/**
@contract
{
"cases": [
{ "$qTargets": 2, "$nDevCostSetup": 1, "$nQaCostSetup": 1, "$nJsolWriteCostSetup": 3, "$nHostAdaptationCostSetup": 0.5, "$nJsolQaCostSetup": 1, "$nDevCostIteration": 0.3, "$nQaCostIteration": 0.5, "$nJsolWriteCostIteration": 0.4, "$nHostAdaptationCostIteration": 0.1, "$nJsolQaCostIteration": 0.3 },
{ "$qTargets": 4, "$nDevCostSetup": 2, "$nQaCostSetup": 0, "$nJsolWriteCostSetup": 7, "$nHostAdaptationCostSetup": 0, "$nJsolQaCostSetup": 0, "$nDevCostIteration": 0.8, "$nQaCostIteration": 0, "$nJsolWriteCostIteration": 20, "$nHostAdaptationCostIteration": 0, "$nJsolQaCostIteration": 0 }
]
}
*/
const $mAdoptionEconomics = function(
$qTargets,
$nDevCostSetup, $nQaCostSetup, $nJsolWriteCostSetup, $nHostAdaptationCostSetup, $nJsolQaCostSetup,
$nDevCostIteration, $nQaCostIteration, $nJsolWriteCostIteration, $nHostAdaptationCostIteration, $nJsolQaCostIteration
) {
const $nSetupCostNative = $qTargets * ($nDevCostSetup + $nQaCostSetup);
const $nSetupCostJsol = $nJsolWriteCostSetup + ($qTargets * $nHostAdaptationCostSetup) + $nJsolQaCostSetup;
const $nIterationCostNative = $qTargets * ($nDevCostIteration + $nQaCostIteration);
const $nIterationCostJsol = $nJsolWriteCostIteration + $nJsolQaCostIteration + ($qTargets * $nHostAdaptationCostIteration);
const $nSetupGap = $nSetupCostJsol - $nSetupCostNative;
const $nPerIterationSavings = $nIterationCostNative - $nIterationCostJsol;
let $sVerdict = "native_always_wins";
let $nBreakEvenIterations = -1;
if ($nPerIterationSavings > 0) {
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
} else {
$sVerdict = "jsol_wins_after_breakeven";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
} else if ($nPerIterationSavings < 0) {
if ($nSetupGap < 0) {
$sVerdict = "jsol_wins_until_expiration";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
// else: JSOL starts even or behind, and gets worse. native_always_wins stands.
} else {
// Iteration costs identical: setup cost alone decides, with no crossover ever.
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
}
// else: native_always_wins stands, permanently parallel, JSOL never catches up.
}
return Map.create(
"verdict", $sVerdict,
"breakEvenIterations", $nBreakEvenIterations,
"setupCostNative", $nSetupCostNative,
"setupCostJsol", $nSetupCostJsol,
"iterationCostNative", $nIterationCostNative,
"iterationCostJsol", $nIterationCostJsol
);
};
// @JSOL v0.2.96
/**
@description
# Adoption Economics - Full Model
Computes whether adopting JSOL for a given algorithm pays for itself,
using the break-even model from **ADOPTION_ECONOMICS.md**. Two paths are
compared: writing the algorithm by hand in every target language
("native"), versus writing it once in JSOL and adapting the compiled
output into each target ("jsol"). Each path has a setup cost (writing
it the first time) and a per-iteration cost (every later change).
## Cost Formulas
`setupCostNative = qTargets * (nDevCostSetup + nQaCostSetup)`
`setupCostJsol = nJsolWriteCostSetup + (qTargets * nHostAdaptationCostSetup) + nJsolQaCostSetup`
`iterationCostNative = qTargets * (nDevCostIteration + nQaCostIteration)`
`iterationCostJsol = nJsolWriteCostIteration + nJsolQaCostIteration + (qTargets * nHostAdaptationCostIteration)`
## Important Note
The naive version of this function returned a single "immediate win"
flag gated only on whether setup was cheaper. **That is wrong**: setup cost
and per-iteration cost can point in opposite directions, and collapsing
them into one flag hides real scenarios. There are four distinct cases,
from crossing `setupGap = setupCostJsol - setupCostNative` and
`perIterationSavings = iterationCostNative - iterationCostJsol`:
- **perIterationSavings > 0, setupGap <= 0**: JSOL cheaper now AND every
iteration going forward. *jsol_wins_always*, breakEven = 0.
- **perIterationSavings > 0, setupGap > 0**: JSOL starts more expensive
but each iteration closes the gap. *jsol_wins_after_breakeven*,
breakEven = setupGap / perIterationSavings (a future point).
- **perIterationSavings < 0, setupGap < 0**: JSOL starts cheaper but each
iteration is MORE expensive than native, eroding the lead.
*jsol_wins_until_expiration*, breakEven = setupGap /
perIterationSavings (a positive number: the point where native
catches back up and overtakes JSOL). A small value here means JSOL
is only cheaper for a sliver of a single iteration in practice.
- **Anything else** (JSOL starts more expensive AND stays more expensive
per iteration, or the two are permanently parallel with no
crossover): *native_always_wins*, breakEven = -1 (no finite point
exists).
## Important Disclaimer
This function makes no judgment about whether an algorithm will
actually see that many iterations; that estimate is the reader's to
make.
## Parameters
- **@param {integer} $qTargets** - N, number of target languages (e.g. 2 for JS+PHP).
- **@param {number} $nDevCostSetup** - D, native dev cost per target, first time.
- **@param {number} $nQaCostSetup** - Q, native QA cost per target, first time.
- **@param {number} $nJsolWriteCostSetup** - S, cost of writing the .jsol file itself, first time.
- **@param {number} $nHostAdaptationCostSetup** - H, cost of wiring compiled output into one target, first time.
- **@param {number} $nJsolQaCostSetup** - Q_jsol, cost of verifying the JSOL algorithm once, first time.
- **@param {number} $nDevCostIteration** - d, native dev cost per target, per later change.
- **@param {number} $nQaCostIteration** - q, native QA cost per target, per later change.
- **@param {number} $nJsolWriteCostIteration** - s, cost of changing the .jsol file, per later change.
- **@param {number} $nHostAdaptationCostIteration** - h, cost of re-wiring one target, per later change.
- **@param {number} $nJsolQaCostIteration** - q_jsol, cost of re-verifying the JSOL algorithm, per later change.
## Returns
- **@returns {Map}** - Returns a map with the following keys:
- **verdict**: One of the four cases above (*jsol_wins_always* | *jsol_wins_after_breakeven* | *jsol_wins_until_expiration* | *native_always_wins*)
- **breakEvenIterations**: -1 when no finite crossover exists
- **setupCostNative**: Total native setup cost
- **setupCostJsol**: Total JSOL setup cost
- **iterationCostNative**: Total native iteration cost
- **iterationCostJsol**: Total JSOL iteration cost
*/
/**
@contract
{
"cases": [
{ "$qTargets": 2, "$nDevCostSetup": 1, "$nQaCostSetup": 1, "$nJsolWriteCostSetup": 3, "$nHostAdaptationCostSetup": 0.5, "$nJsolQaCostSetup": 1, "$nDevCostIteration": 0.3, "$nQaCostIteration": 0.5, "$nJsolWriteCostIteration": 0.4, "$nHostAdaptationCostIteration": 0.1, "$nJsolQaCostIteration": 0.3 },
{ "$qTargets": 4, "$nDevCostSetup": 2, "$nQaCostSetup": 0, "$nJsolWriteCostSetup": 7, "$nHostAdaptationCostSetup": 0, "$nJsolQaCostSetup": 0, "$nDevCostIteration": 0.8, "$nQaCostIteration": 0, "$nJsolWriteCostIteration": 20, "$nHostAdaptationCostIteration": 0, "$nJsolQaCostIteration": 0 }
]
}
*/
const $mAdoptionEconomics = function(
$qTargets,
$nDevCostSetup, $nQaCostSetup, $nJsolWriteCostSetup, $nHostAdaptationCostSetup, $nJsolQaCostSetup,
$nDevCostIteration, $nQaCostIteration, $nJsolWriteCostIteration, $nHostAdaptationCostIteration, $nJsolQaCostIteration
) {
const $nSetupCostNative = $qTargets * ($nDevCostSetup + $nQaCostSetup);
const $nSetupCostJsol = $nJsolWriteCostSetup + ($qTargets * $nHostAdaptationCostSetup) + $nJsolQaCostSetup;
const $nIterationCostNative = $qTargets * ($nDevCostIteration + $nQaCostIteration);
const $nIterationCostJsol = $nJsolWriteCostIteration + $nJsolQaCostIteration + ($qTargets * $nHostAdaptationCostIteration);
const $nSetupGap = $nSetupCostJsol - $nSetupCostNative;
const $nPerIterationSavings = $nIterationCostNative - $nIterationCostJsol;
let $sVerdict = "native_always_wins";
let $nBreakEvenIterations = -1;
if ($nPerIterationSavings > 0) {
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
}
else {
$sVerdict = "jsol_wins_after_breakeven";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
}
else if ($nPerIterationSavings < 0) {
if ($nSetupGap < 0) {
$sVerdict = "jsol_wins_until_expiration";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
// else: JSOL starts even or behind, and gets worse. native_always_wins stands.
}
else {
// Iteration costs identical: setup cost alone decides, with no crossover ever.
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
}
// else: native_always_wins stands, permanently parallel, JSOL never catches up.
}
return JSOL.dict(
"verdict", $sVerdict,
"breakEvenIterations", $nBreakEvenIterations,
"setupCostNative", $nSetupCostNative,
"setupCostJsol", $nSetupCostJsol,
"iterationCostNative", $nIterationCostNative,
"iterationCostJsol", $nIterationCostJsol
);
};
window['$mAdoptionEconomics'] = $mAdoptionEconomics;
<?php
// @JSOL v0.2.96
/**
@description
# Adoption Economics - Full Model
Computes whether adopting JSOL for a given algorithm pays for itself,
using the break-even model from **ADOPTION_ECONOMICS.md**. Two paths are
compared: writing the algorithm by hand in every target language
("native"), versus writing it once in JSOL and adapting the compiled
output into each target ("jsol"). Each path has a setup cost (writing
it the first time) and a per-iteration cost (every later change).
## Cost Formulas
`setupCostNative = qTargets * (nDevCostSetup + nQaCostSetup)`
`setupCostJsol = nJsolWriteCostSetup + (qTargets * nHostAdaptationCostSetup) + nJsolQaCostSetup`
`iterationCostNative = qTargets * (nDevCostIteration + nQaCostIteration)`
`iterationCostJsol = nJsolWriteCostIteration + nJsolQaCostIteration + (qTargets * nHostAdaptationCostIteration)`
## Important Note
The naive version of this function returned a single "immediate win"
flag gated only on whether setup was cheaper. **That is wrong**: setup cost
and per-iteration cost can point in opposite directions, and collapsing
them into one flag hides real scenarios. There are four distinct cases,
from crossing `setupGap = setupCostJsol - setupCostNative` and
`perIterationSavings = iterationCostNative - iterationCostJsol`:
- **perIterationSavings > 0, setupGap <= 0**: JSOL cheaper now AND every
iteration going forward. *jsol_wins_always*, breakEven = 0.
- **perIterationSavings > 0, setupGap > 0**: JSOL starts more expensive
but each iteration closes the gap. *jsol_wins_after_breakeven*,
breakEven = setupGap / perIterationSavings (a future point).
- **perIterationSavings < 0, setupGap < 0**: JSOL starts cheaper but each
iteration is MORE expensive than native, eroding the lead.
*jsol_wins_until_expiration*, breakEven = setupGap /
perIterationSavings (a positive number: the point where native
catches back up and overtakes JSOL). A small value here means JSOL
is only cheaper for a sliver of a single iteration in practice.
- **Anything else** (JSOL starts more expensive AND stays more expensive
per iteration, or the two are permanently parallel with no
crossover): *native_always_wins*, breakEven = -1 (no finite point
exists).
## Important Disclaimer
This function makes no judgment about whether an algorithm will
actually see that many iterations; that estimate is the reader's to
make.
## Parameters
- **@param {integer} $qTargets** - N, number of target languages (e.g. 2 for JS+PHP).
- **@param {number} $nDevCostSetup** - D, native dev cost per target, first time.
- **@param {number} $nQaCostSetup** - Q, native QA cost per target, first time.
- **@param {number} $nJsolWriteCostSetup** - S, cost of writing the .jsol file itself, first time.
- **@param {number} $nHostAdaptationCostSetup** - H, cost of wiring compiled output into one target, first time.
- **@param {number} $nJsolQaCostSetup** - Q_jsol, cost of verifying the JSOL algorithm once, first time.
- **@param {number} $nDevCostIteration** - d, native dev cost per target, per later change.
- **@param {number} $nQaCostIteration** - q, native QA cost per target, per later change.
- **@param {number} $nJsolWriteCostIteration** - s, cost of changing the .jsol file, per later change.
- **@param {number} $nHostAdaptationCostIteration** - h, cost of re-wiring one target, per later change.
- **@param {number} $nJsolQaCostIteration** - q_jsol, cost of re-verifying the JSOL algorithm, per later change.
## Returns
- **@returns {Map}** - Returns a map with the following keys:
- **verdict**: One of the four cases above (*jsol_wins_always* | *jsol_wins_after_breakeven* | *jsol_wins_until_expiration* | *native_always_wins*)
- **breakEvenIterations**: -1 when no finite crossover exists
- **setupCostNative**: Total native setup cost
- **setupCostJsol**: Total JSOL setup cost
- **iterationCostNative**: Total native iteration cost
- **iterationCostJsol**: Total JSOL iteration cost
*/
/**
@contract
{
"cases": [
{ "$qTargets": 2, "$nDevCostSetup": 1, "$nQaCostSetup": 1, "$nJsolWriteCostSetup": 3, "$nHostAdaptationCostSetup": 0.5, "$nJsolQaCostSetup": 1, "$nDevCostIteration": 0.3, "$nQaCostIteration": 0.5, "$nJsolWriteCostIteration": 0.4, "$nHostAdaptationCostIteration": 0.1, "$nJsolQaCostIteration": 0.3 },
{ "$qTargets": 4, "$nDevCostSetup": 2, "$nQaCostSetup": 0, "$nJsolWriteCostSetup": 7, "$nHostAdaptationCostSetup": 0, "$nJsolQaCostSetup": 0, "$nDevCostIteration": 0.8, "$nQaCostIteration": 0, "$nJsolWriteCostIteration": 20, "$nHostAdaptationCostIteration": 0, "$nJsolQaCostIteration": 0 }
]
}
*/
$mAdoptionEconomics = function(
$qTargets,
$nDevCostSetup, $nQaCostSetup, $nJsolWriteCostSetup, $nHostAdaptationCostSetup, $nJsolQaCostSetup,
$nDevCostIteration, $nQaCostIteration, $nJsolWriteCostIteration, $nHostAdaptationCostIteration, $nJsolQaCostIteration
) {
$nSetupCostNative = $qTargets * ($nDevCostSetup + $nQaCostSetup);
$nSetupCostJsol = $nJsolWriteCostSetup + ($qTargets * $nHostAdaptationCostSetup) + $nJsolQaCostSetup;
$nIterationCostNative = $qTargets * ($nDevCostIteration + $nQaCostIteration);
$nIterationCostJsol = $nJsolWriteCostIteration + $nJsolQaCostIteration + ($qTargets * $nHostAdaptationCostIteration);
$nSetupGap = $nSetupCostJsol - $nSetupCostNative;
$nPerIterationSavings = $nIterationCostNative - $nIterationCostJsol;
$sVerdict = "native_always_wins";
$nBreakEvenIterations = -1;
if ($nPerIterationSavings > 0) {
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
}
else {
$sVerdict = "jsol_wins_after_breakeven";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
}
else if ($nPerIterationSavings < 0) {
if ($nSetupGap < 0) {
$sVerdict = "jsol_wins_until_expiration";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
// else: JSOL starts even or behind, and gets worse. native_always_wins stands.
}
else {
// Iteration costs identical: setup cost alone decides, with no crossover ever.
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
}
// else: native_always_wins stands, permanently parallel, JSOL never catches up.
}
return JSOL::dict(
"verdict", $sVerdict,
"breakEvenIterations", $nBreakEvenIterations,
"setupCostNative", $nSetupCostNative,
"setupCostJsol", $nSetupCostJsol,
"iterationCostNative", $nIterationCostNative,
"iterationCostJsol", $nIterationCostJsol
);
};
declare var JSOL: any;
declare var Rgx: any;
// @JSOL v0.2.96
/**
@description
# Adoption Economics - Full Model
Computes whether adopting JSOL for a given algorithm pays for itself,
using the break-even model from **ADOPTION_ECONOMICS.md**. Two paths are
compared: writing the algorithm by hand in every target language
("native"), versus writing it once in JSOL and adapting the compiled
output into each target ("jsol"). Each path has a setup cost (writing
it the first time) and a per-iteration cost (every later change).
## Cost Formulas
`setupCostNative = qTargets * (nDevCostSetup + nQaCostSetup)`
`setupCostJsol = nJsolWriteCostSetup + (qTargets * nHostAdaptationCostSetup) + nJsolQaCostSetup`
`iterationCostNative = qTargets * (nDevCostIteration + nQaCostIteration)`
`iterationCostJsol = nJsolWriteCostIteration + nJsolQaCostIteration + (qTargets * nHostAdaptationCostIteration)`
## Important Note
The naive version of this function returned a single "immediate win"
flag gated only on whether setup was cheaper. **That is wrong**: setup cost
and per-iteration cost can point in opposite directions, and collapsing
them into one flag hides real scenarios. There are four distinct cases,
from crossing `setupGap = setupCostJsol - setupCostNative` and
`perIterationSavings = iterationCostNative - iterationCostJsol`:
- **perIterationSavings > 0, setupGap <= 0**: JSOL cheaper now AND every
iteration going forward. *jsol_wins_always*, breakEven = 0.
- **perIterationSavings > 0, setupGap > 0**: JSOL starts more expensive
but each iteration closes the gap. *jsol_wins_after_breakeven*,
breakEven = setupGap / perIterationSavings (a future point).
- **perIterationSavings < 0, setupGap < 0**: JSOL starts cheaper but each
iteration is MORE expensive than native, eroding the lead.
*jsol_wins_until_expiration*, breakEven = setupGap /
perIterationSavings (a positive number: the point where native
catches back up and overtakes JSOL). A small value here means JSOL
is only cheaper for a sliver of a single iteration in practice.
- **Anything else** (JSOL starts more expensive AND stays more expensive
per iteration, or the two are permanently parallel with no
crossover): *native_always_wins*, breakEven = -1 (no finite point
exists).
## Important Disclaimer
This function makes no judgment about whether an algorithm will
actually see that many iterations; that estimate is the reader's to
make.
## Parameters
- **@param {integer} $qTargets** - N, number of target languages (e.g. 2 for JS+PHP).
- **@param {number} $nDevCostSetup** - D, native dev cost per target, first time.
- **@param {number} $nQaCostSetup** - Q, native QA cost per target, first time.
- **@param {number} $nJsolWriteCostSetup** - S, cost of writing the .jsol file itself, first time.
- **@param {number} $nHostAdaptationCostSetup** - H, cost of wiring compiled output into one target, first time.
- **@param {number} $nJsolQaCostSetup** - Q_jsol, cost of verifying the JSOL algorithm once, first time.
- **@param {number} $nDevCostIteration** - d, native dev cost per target, per later change.
- **@param {number} $nQaCostIteration** - q, native QA cost per target, per later change.
- **@param {number} $nJsolWriteCostIteration** - s, cost of changing the .jsol file, per later change.
- **@param {number} $nHostAdaptationCostIteration** - h, cost of re-wiring one target, per later change.
- **@param {number} $nJsolQaCostIteration** - q_jsol, cost of re-verifying the JSOL algorithm, per later change.
## Returns
- **@returns {Map}** - Returns a map with the following keys:
- **verdict**: One of the four cases above (*jsol_wins_always* | *jsol_wins_after_breakeven* | *jsol_wins_until_expiration* | *native_always_wins*)
- **breakEvenIterations**: -1 when no finite crossover exists
- **setupCostNative**: Total native setup cost
- **setupCostJsol**: Total JSOL setup cost
- **iterationCostNative**: Total native iteration cost
- **iterationCostJsol**: Total JSOL iteration cost
*/
/**
@contract
{
"cases": [
{ "$qTargets": 2, "$nDevCostSetup": 1, "$nQaCostSetup": 1, "$nJsolWriteCostSetup": 3, "$nHostAdaptationCostSetup": 0.5, "$nJsolQaCostSetup": 1, "$nDevCostIteration": 0.3, "$nQaCostIteration": 0.5, "$nJsolWriteCostIteration": 0.4, "$nHostAdaptationCostIteration": 0.1, "$nJsolQaCostIteration": 0.3 },
{ "$qTargets": 4, "$nDevCostSetup": 2, "$nQaCostSetup": 0, "$nJsolWriteCostSetup": 7, "$nHostAdaptationCostSetup": 0, "$nJsolQaCostSetup": 0, "$nDevCostIteration": 0.8, "$nQaCostIteration": 0, "$nJsolWriteCostIteration": 20, "$nHostAdaptationCostIteration": 0, "$nJsolQaCostIteration": 0 }
]
}
*/
const $mAdoptionEconomics = function($qTargets: any, $nDevCostSetup: any, $nQaCostSetup: any, $nJsolWriteCostSetup: any, $nHostAdaptationCostSetup: any, $nJsolQaCostSetup: any, $nDevCostIteration: any, $nQaCostIteration: any, $nJsolWriteCostIteration: any, $nHostAdaptationCostIteration: any, $nJsolQaCostIteration: any): Record<string, any> {
const $nSetupCostNative: number = $qTargets * ($nDevCostSetup + $nQaCostSetup);
const $nSetupCostJsol: number = $nJsolWriteCostSetup + ($qTargets * $nHostAdaptationCostSetup) + $nJsolQaCostSetup;
const $nIterationCostNative: number = $qTargets * ($nDevCostIteration + $nQaCostIteration);
const $nIterationCostJsol: number = $nJsolWriteCostIteration + $nJsolQaCostIteration + ($qTargets * $nHostAdaptationCostIteration);
const $nSetupGap: number = $nSetupCostJsol - $nSetupCostNative;
const $nPerIterationSavings: number = $nIterationCostNative - $nIterationCostJsol;
let $sVerdict: string = "native_always_wins";
let $nBreakEvenIterations: number = -1;
if ($nPerIterationSavings > 0) {
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
}
else {
$sVerdict = "jsol_wins_after_breakeven";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
}
else if ($nPerIterationSavings < 0) {
if ($nSetupGap < 0) {
$sVerdict = "jsol_wins_until_expiration";
$nBreakEvenIterations = $nSetupGap / $nPerIterationSavings;
}
// else: JSOL starts even or behind, and gets worse. native_always_wins stands.
}
else {
// Iteration costs identical: setup cost alone decides, with no crossover ever.
if ($nSetupGap <= 0) {
$sVerdict = "jsol_wins_always";
$nBreakEvenIterations = 0;
}
// else: native_always_wins stands, permanently parallel, JSOL never catches up.
}
return JSOL.dict(
"verdict", $sVerdict,
"breakEvenIterations", $nBreakEvenIterations,
"setupCostNative", $nSetupCostNative,
"setupCostJsol", $nSetupCostJsol,
"iterationCostNative", $nIterationCostNative,
"iterationCostJsol", $nIterationCostJsol
);
};
import math
from jsol_core import JSOL
# @JSOL v0.2.96
#*
# @description
#
# # Adoption Economics - Full Model
#
# Computes whether adopting JSOL for a given algorithm pays for itself,
# using the break-even model from **ADOPTION_ECONOMICS.md**. Two paths are
# compared: writing the algorithm by hand in every target language
# ("native"), versus writing it once in JSOL and adapting the compiled
# output into each target ("jsol"). Each path has a setup cost (writing
# it the first time) and a per-iteration cost (every later change).
#
# ## Cost Formulas
#
# `setupCostNative = qTargets * (nDevCostSetup + nQaCostSetup)`
# `setupCostJsol = nJsolWriteCostSetup + (qTargets * nHostAdaptationCostSetup) + nJsolQaCostSetup`
# `iterationCostNative = qTargets * (nDevCostIteration + nQaCostIteration)`
# `iterationCostJsol = nJsolWriteCostIteration + nJsolQaCostIteration + (qTargets * nHostAdaptationCostIteration)`
#
# ## Important Note
#
# The naive version of this function returned a single "immediate win"
# flag gated only on whether setup was cheaper. **That is wrong**: setup cost
# and per-iteration cost can point in opposite directions, and collapsing
# them into one flag hides real scenarios. There are four distinct cases,
# from crossing `setupGap = setupCostJsol - setupCostNative` and
# `perIterationSavings = iterationCostNative - iterationCostJsol`:
#
# - **perIterationSavings > 0, setupGap <= 0**: JSOL cheaper now AND every
# iteration going forward. *jsol_wins_always*, breakEven = 0.
#
# - **perIterationSavings > 0, setupGap > 0**: JSOL starts more expensive
# but each iteration closes the gap. *jsol_wins_after_breakeven*,
# breakEven = setupGap / perIterationSavings (a future point).
#
# - **perIterationSavings < 0, setupGap < 0**: JSOL starts cheaper but each
# iteration is MORE expensive than native, eroding the lead.
# *jsol_wins_until_expiration*, breakEven = setupGap /
# perIterationSavings (a positive number: the point where native
# catches back up and overtakes JSOL). A small value here means JSOL
# is only cheaper for a sliver of a single iteration in practice.
#
# - **Anything else** (JSOL starts more expensive AND stays more expensive
# per iteration, or the two are permanently parallel with no
# crossover): *native_always_wins*, breakEven = -1 (no finite point
# exists).
#
# ## Important Disclaimer
#
# This function makes no judgment about whether an algorithm will
# actually see that many iterations; that estimate is the reader's to
# make.
#
# ## Parameters
#
# - **@param {integer} $qTargets** - N, number of target languages (e.g. 2 for JS+PHP).
# - **@param {number} $nDevCostSetup** - D, native dev cost per target, first time.
# - **@param {number} $nQaCostSetup** - Q, native QA cost per target, first time.
# - **@param {number} $nJsolWriteCostSetup** - S, cost of writing the .jsol file itself, first time.
# - **@param {number} $nHostAdaptationCostSetup** - H, cost of wiring compiled output into one target, first time.
# - **@param {number} $nJsolQaCostSetup** - Q_jsol, cost of verifying the JSOL algorithm once, first time.
# - **@param {number} $nDevCostIteration** - d, native dev cost per target, per later change.
# - **@param {number} $nQaCostIteration** - q, native QA cost per target, per later change.
# - **@param {number} $nJsolWriteCostIteration** - s, cost of changing the .jsol file, per later change.
# - **@param {number} $nHostAdaptationCostIteration** - h, cost of re-wiring one target, per later change.
# - **@param {number} $nJsolQaCostIteration** - q_jsol, cost of re-verifying the JSOL algorithm, per later change.
#
# ## Returns
#
# - **@returns {Map}** - Returns a map with the following keys:
# - **verdict**: One of the four cases above (*jsol_wins_always* | *jsol_wins_after_breakeven* | *jsol_wins_until_expiration* | *native_always_wins*)
# - **breakEvenIterations**: -1 when no finite crossover exists
# - **setupCostNative**: Total native setup cost
# - **setupCostJsol**: Total JSOL setup cost
# - **iterationCostNative**: Total native iteration cost
# - **iterationCostJsol**: Total JSOL iteration cost
#
#*
# @contract
# {
# "cases": [
# { "$qTargets": 2, "$nDevCostSetup": 1, "$nQaCostSetup": 1, "$nJsolWriteCostSetup": 3, "$nHostAdaptationCostSetup": 0.5, "$nJsolQaCostSetup": 1, "$nDevCostIteration": 0.3, "$nQaCostIteration": 0.5, "$nJsolWriteCostIteration": 0.4, "$nHostAdaptationCostIteration": 0.1, "$nJsolQaCostIteration": 0.3 },
# { "$qTargets": 4, "$nDevCostSetup": 2, "$nQaCostSetup": 0, "$nJsolWriteCostSetup": 7, "$nHostAdaptationCostSetup": 0, "$nJsolQaCostSetup": 0, "$nDevCostIteration": 0.8, "$nQaCostIteration": 0, "$nJsolWriteCostIteration": 20, "$nHostAdaptationCostIteration": 0, "$nJsolQaCostIteration": 0 }
# ]
# }
#
def mAdoptionEconomics(
qTargets,
nDevCostSetup, nQaCostSetup, nJsolWriteCostSetup, nHostAdaptationCostSetup, nJsolQaCostSetup,
nDevCostIteration, nQaCostIteration, nJsolWriteCostIteration, nHostAdaptationCostIteration, nJsolQaCostIteration
):
nSetupCostNative = qTargets * (nDevCostSetup + nQaCostSetup);
nSetupCostJsol = nJsolWriteCostSetup + (qTargets * nHostAdaptationCostSetup) + nJsolQaCostSetup;
nIterationCostNative = qTargets * (nDevCostIteration + nQaCostIteration);
nIterationCostJsol = nJsolWriteCostIteration + nJsolQaCostIteration + (qTargets * nHostAdaptationCostIteration);
nSetupGap = nSetupCostJsol - nSetupCostNative;
nPerIterationSavings = nIterationCostNative - nIterationCostJsol;
sVerdict = "native_always_wins";
nBreakEvenIterations = -1;
if nPerIterationSavings > 0:
if nSetupGap <= 0:
sVerdict = "jsol_wins_always";
nBreakEvenIterations = 0;
else:
sVerdict = "jsol_wins_after_breakeven";
nBreakEvenIterations = nSetupGap / nPerIterationSavings;
elif nPerIterationSavings < 0:
if nSetupGap < 0:
sVerdict = "jsol_wins_until_expiration";
nBreakEvenIterations = nSetupGap / nPerIterationSavings;
# else: JSOL starts even or behind, and gets worse. native_always_wins stands.
else:
# Iteration costs identical: setup cost alone decides, with no crossover ever.
if nSetupGap <= 0:
sVerdict = "jsol_wins_always";
nBreakEvenIterations = 0;
# else: native_always_wins stands, permanently parallel, JSOL never catches up.
return JSOL.dict(
"verdict", sVerdict,
"breakEvenIterations", nBreakEvenIterations,
"setupCostNative", nSetupCostNative,
"setupCostJsol", nSetupCostJsol,
"iterationCostNative", nIterationCostNative,
"iterationCostJsol", nIterationCostJsol
);
Each example started as a test.
The language and compiler improved because of what these examples demanded. The CLRS examples are here for the same reason: if JSOL aims to be a language someone can read rather than just compile, it has to survive contact with computer science, not just invoicing.
Strict Validation
Finance & Rules
Computer Science
What JSOL is NOT
JSOL is not a full-stack framework, and it's not a general-purpose language. It is an isolated, pure, synchronous calculator.
It doesn't touch the DOM, it doesn't make network requests (no fetch or Async), and it doesn't talk to databases.
Every alternative to JSOL (like Haxe or WebAssembly) buys generality or performance at the cost of requiring a toolchain. JSOL buys zero-toolchain portability by aggressively restricting what you can write.
The Honest Tradeoffs (Where JSOL is worse)
JSOL costs more to write than a native implementation. These are the engine-level restrictions you accept when using it:
| Feature | Native JS / PHP | JSOL | Why it was stripped |
|---|---|---|---|
| Developer Speed | Fast (Syntactic sugar, functional methods) | Slower (Spartan syntax, mandatory imperative loops) | Functional arrays and sugar don't map 1:1 across engines without AST pipelines. |
| Control Flow | Async, Promises, Threads | Strictly Synchronous (Single-thread blocking) | Async control flow has no shared syntax between JS and PHP. |
| State & OOP | Classes, this, Prototypes |
Flat Dicts & Primitives (Higher GC pressure) | Classes diverge wildly. Forbidding them guarantees O(1) property access but forces state copying for large loops. |
| Text Parsing | Native Regex (PCRE / V8) | Procedural loops only (No native regex) | Regex engines differ. Complex patterns can cause ReDoS in one engine but not another. |
Design Pillars
Four principles shape every rule in the specification.
1. Clarity
A JSOL algorithm has to be readable by the person who owns the business logic, not just by a compiler.
This is also why JSOL doesn't standardize how you structure code (nested functions vs. flat scope, for instance) — that's implementation shape, not business logic.
2. Portability
The same source runs correctly on every proven target.
This is where Deterministic Parity comes from: given identical inputs, every target's output has to match, bit for bit.
3. Performance
The compiled output should be no heavier and no slower than it has to be.
This is where Zero Dead Code comes from: nothing gets shipped that a given file doesn't actually use.
4. Developer Experience
Writing, compiling, and debugging JSOL should be as frictionless as the constraints allow.
This is where the AST-free compiler pipeline and Zero Runtime Dependencies come from.
This is an open problem, not a finished product
JSOL works today for JavaScript, PHP, TypeScript and Python. The compiler is self-hosting (i.e., it compiles itself) and the fixed-point convergence tests prove that the output is stable across generations and hosts. But the really interesting work is what comes next.
The project's real bet is that the same approach can extend to other targets. TypeScript, Go, C#, Python, Rust, C: each one is a separate compiler backend, and each one teaches you something different about what "portable business logic" actually requires.
If you're a CS educator or student, EXTENDING.md lays out the feasibility matrix, the JSOL-C leverage effect, and the specific compiler design problems involved.
Fork it. Break it. Build a target. The compiler architecture is deliberately modular: adding a language means writing one compiler file, not rewriting the core.